home *** CD-ROM | disk | FTP | other *** search
/ MacFormat España 27 / MacFormat n. 27 (Spain) / Mac Format 26.bin / Shareware / Programación / Word Services XCMD 1.0d3 / Sources / FindSpeller.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-01-18  |  1.4 KB  |  74 lines

  1. /* FindSpeller.c
  2.  * Look for and launch an application with the given creator code.
  3.  * Copyright ©1996 Michael D. Crawford.  All Rights Reserved.
  4.  * You may use this code on the condition that you read the following web page:
  5.  * http://www.webcom.com/wordserv/
  6.  *  1 Jul 96 Mike Crawford crawford@scruznet.com
  7.  */
  8.  
  9. #include "FindSpeller.h"
  10. #include "FindProcess.h"
  11. #include "SearchForApp.h"
  12.  
  13. OSErr FindSpeller( OSType creator, Boolean *foundIt )
  14. {
  15.     OSErr    err;
  16.     short    i;
  17.     Boolean    gotIt;
  18.     ProcessSerialNumber psn;
  19.     ProcessInfoRec pInfo;
  20.     FSSpec fSpec;
  21.     Str255    procName;
  22.     VolumeParam    vPB;
  23.     OSType    *ptr;
  24.     OSType    **fakeHandle;
  25.     OSType    buf;
  26.     
  27.     *foundIt = false;
  28.     
  29.     gotIt = FindAProcess( creator,
  30.                             &psn,
  31.                             &pInfo,
  32.                             &fSpec,
  33.                             procName );
  34.     if ( gotIt ){
  35.         *foundIt = true;
  36.         return noErr;
  37.     }
  38.     
  39.     vPB.ioCompletion = (IOCompletionUPP)NULL;
  40.     vPB.ioVolIndex = 1;
  41.     vPB.ioNamePtr = (StringPtr)NULL;
  42.     
  43.     ptr = &creator;
  44.     fakeHandle = &ptr;
  45.     
  46.     do {
  47.         err = PBGetVInfoSync( (ParamBlockRec*)&vPB );
  48.         if ( err == nsvErr )
  49.             return noErr;            // Out of volumes to search, haven't found any browsers
  50.         if ( err )
  51.             return err;
  52.         
  53.         err = SearchVolForBrowser( vPB.ioVRefNum,
  54.                                     &gotIt,
  55.                                     fakeHandle, 
  56.                                     1, 
  57.                                     &fSpec, 
  58.                                     &buf );
  59.         if ( gotIt ){
  60.             err = LaunchTheApp( &fSpec );
  61.             
  62.             if ( !err )
  63.                 *foundIt = true;
  64.             return err;
  65.                 
  66.         }
  67.         
  68.         vPB.ioVolIndex++;
  69.     }while( !err && !gotIt );
  70.         
  71.     return noErr;
  72. }
  73.  
  74.